﻿using GeneradorDeNumerosAleatorios.Generadores_Uniformes;

namespace GeneradorDeNumerosAleatorios.Utilities
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// A public and static class to manipulate strings, and get the desired portion of another string.
    /// </summary>
    public static class StringManipulator
    {
        /// <summary>
        /// Method to get the central numbers for the given string.
        /// This method is used by <see cref="MidSquare"/> to get the central numbers of a given number.
        /// </summary>
        /// <param name="squareSeed">The square of the seed converted to a string.</param>
        /// <param name="middleNumber">The middle of the seed.</param>
        /// <param name="digitsQuantity">Quantity of digits that wants to be generated.</param>
        /// <returns></returns>
        public static string GetCentralNumbers(string squareSeed, int middleNumber, int digitsQuantity)
        {
            string response = null;

            for (int i = 0; i < squareSeed.Length; i++)
            {
                if (i < middleNumber && middleNumber - i <= digitsQuantity)
                {
                    response = response + squareSeed[i];
                }
                else
                {
                    if (i >= middleNumber && i - middleNumber < digitsQuantity)
                    {
                        response = response + squareSeed[i];
                    }
                }
            }

            return response;
        }
    }
}
